package com.chenliwu.demo.annotation.example2;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @author chenliwu
 * @since 2022-04-05
 */
public class TestCustomParameter {

    public static void fun1(@CustomParameter String param1, @CustomParameter String param2) {
    }


    public static void main(String[] args) {
        testMethodParamAnnotation();
    }

    static void testMethodParamAnnotation() {
        try {
            Method method = TestCustomParameter.class.getDeclaredMethod("fun1", String.class, String.class);

            Parameter[] parameters = method.getParameters();
            for (Parameter parameter : parameters) {
                System.out.println("parameter.getName():" + parameter.getName());
                System.out.println("parameter.getType():" + parameter.getType());
                if (parameter.isAnnotationPresent(CustomParameter.class)) {
                    System.out.println("CustomParameter parameter");
                }
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

}
